package com.longnuoqi.mydoctor.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import android.widget.TextView;

import com.longnuoqi.mydoctor.entity.News;
import com.yunhe.mydoctor.R;

import java.util.List;

/**
 * Created by Lenovo on 2015/12/25.
 */
public class NewsRelateListAdapter extends BaseAdapter {
    private List<News> list;
    private Context context;
    private LayoutInflater inflater;

    private int id;
    private String url;

    public NewsRelateListAdapter(Context context, List<News> list) {
        this.context = context;
        this.list = list;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        if (list.size() != 0) {
            return list.size();
        } else return 0;
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.news_relate_listview_item, null);
            holder.title = (TextView) convertView.findViewById(R.id.news_relate_lv_txt);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.title.setText(list.get(position).getTitle());
        holder.title.setTag(list.get(position).getId());
        return convertView;
    }

    private class ViewHolder {
        public TextView title;
    }
}
